package com.twu.biblioteca.command;

import com.twu.biblioteca.exception.InvalidSelectionException;

import java.util.HashMap;
import java.util.LinkedHashMap;


public class CommandFactory {
    private static HashMap<Option, Command> map = new LinkedHashMap<Option, Command>();

    static {
        map.put(Option.SHOW_BOOK, Option.SHOW_BOOK.getCommand());
        map.put(Option.RESERVE_BOOK, Option.RESERVE_BOOK.getCommand());
        map.put(Option.SHOW_MEMBER_DETAIL, Option.SHOW_MEMBER_DETAIL.getCommand());
        map.put(Option.SHOW_MOVIE, Option.SHOW_MOVIE.getCommand());
        map.put(Option.QUIT, Option.QUIT.getCommand());

    }

    public static Command createCommand(String option) throws InvalidSelectionException {
        Option optionCommand = Option.getOptionByInput(option);
        if (map.get(optionCommand) != null) {
            return map.get(optionCommand);
        } else {
            throw new InvalidSelectionException(InvalidSelectionException.INVALID_OPTION);
        }
    }

    public static HashMap<Option, Command> getOptions() {
        return map;
    }
}
